﻿@using Webdiyer.WebControls.Mvc
@model PagedList<NationalIT.Equipment>
<h3>
    Equipment</h3>
<div class="f_req">@ViewBag.Error</div>
<div class="row-fluid">
    <div class="span12">
        <div class="row-fluid">
            <div class="span12">
                @Html.Partial("_MenuButtonNewEditOrDelete")
            </div>
        </div>
        <table class="table">
            <tr>
                <th>
                    <input type="checkbox" name="" value="" class="checkAll" />
                </th>
                <th>
                    ID
                </th>
                <th>
                    Type
                </th>
                <th>
                    Equipment Number
                </th>
                <th>
                    Owner
                </th>
                <th>
                    Driver
                </th>
                <th>
                    VIN
                </th>
                <th>
                    Registion Expiration
                </th>
            </tr>
            @{
                var db = NationalIT.DB.Entities;
                NationalIT.Owners owner = null;
                NationalIT.Driver_Info driver = null;
            }
            @foreach (var item in Model)
            {
                owner = db.Owners.FirstOrDefault(m => m.OwnerID == item.Owner);
                driver = db.Driver_Info.FirstOrDefault(m => m.ID == item.Driver);
            
                <tr>
                    <td>
                        <input type="checkbox" name="checkOwner" value="@item.ID" class="checkitem"/>
                    </td>
                    <td>
                        @Html.ActionLink(item.ID.ToString(), "NewOrEdit", new { id = item.ID })
                    </td>
                    <td>
                        @item.Equipment_Type
                    </td>
                    <td>
                        @item.Equipment_number
                    </td>
                    <td>
                        @(owner != null ? owner.Name : null)
                    </td>
                    <td>
                        @(driver != null ? driver.First_name + " " + driver.Last_name : null)
                    </td>
                    <td>
                        @item.VIN
                    </td>
                    <td>
                        @(item.Registration_Expiration.HasValue ? item.Registration_Expiration.Value.ToString("MM/dd/yyyy") : "")
                    </td>
                </tr>
            }
        </table>
        <div class="row-fluid">
            <div class="span4">
                <div class="dataTables_info">
                    @if (Model.TotalItemCount > 0)
                    {
                        if (Model.TotalItemCount < Model.PageSize)
                        {
                        <span>1 </span>
                        <span>- </span>@Model.TotalItemCount
                        }
                        else
                        {
                        <span></span>@((Model.CurrentPageIndex - 1) * Model.PageSize + 1)
                        <span>- </span>@((Model.CurrentPageIndex != Model.TotalPageCount) ? (Model.CurrentPageIndex * Model.PageSize) : Math.Abs((Model.CurrentPageIndex) * Model.PageSize - (Model.PageSize * Model.TotalPageCount) - Model.TotalItemCount))
                        }
                        <span>of </span>@(Model.TotalItemCount)                            
                    }
                </div>
            </div>
            <div class="span8">
                <div class="dataTables_paginate paging_bootstrap pagination phantrangmvcpager">
                    @Html.Pager(Model, new PagerOptions { ContainerTagName = "ul", PageIndexParameterName = "page", CurrentPagerItemWrapperFormatString = "<li class='active'>{0}</li>", CurrentPageNumberFormatString = "{0}", FirstPageText = "&laquo; ", LastPageText = " &raquo;", NextPageText = "Next →", PrevPageText = "← Prev", SeparatorHtml = "" })
                </div>
            </div>
        </div>
    </div>
</div>
